# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=wscript
pkgver=201.0410be2
pkgrel=1
pkgdesc='Emulator/tracer of the Windows Script Host functionality.'
arch=('any')
groups=('blackarch' 'blackarch-code-audit')
url='https://github.com/mrpapercut/wscript'
license=('MIT')
depends=('xdg-utils')
makedepends=('npm' 'git')
source=("git+https://github.com/mrpapercut/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  npm install
  npm run build
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
if xdg-open /usr/share/$pkgname/dist/index.html ; then
  continue
else
  echo "Open the following link in your browser: file:///usr/share/wscript/dist/index.html"
fi
EOF
  chmod +x "$pkgdir/usr/bin/$pkgname"
}

